package com.tianbao54.kotlin_01

class Person constructor(username: String) {

    // java 中没有给初值，会有默认的初始值，而 kotlin 必须赋予初始值。
    private var username: String
    private var age: Int
    private var address: String

    init {
        // 构造方法中的初始值
        println(username)
        this.username = username
        this.age = 20
        this.address = "nanchang"
    }

    // secondary constructor 必须直接或者间接的调用 primary 构造方法
    // :this 调用 primary 构造方法
    constructor(username: String, age: Int) : this(username) {
        println("username = $username , age = $age")
        this.username = username
        this.age = age
        this.address = "shanghai"
    }

    constructor(username: String, age: Int, address: String) : this(username, age) {
        this.address = address
    }

    fun printlnInfo() {
        println("username = ${this.username} , age = ${this.age} , address = ${this.address}")
    }
}

fun main(args: Array<String>) {

    var person = Person("zhangsan")
    var person2 = Person("lisi", 30)
    var person3 = Person("wangwu", 22, "beijing")
}